<!doctype html>
<html>
	<head>
		<title>Druid SQL Stat</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
		<link href='css/bootstrap.min.css' rel="stylesheet" />
		<link href="css/style.css" type="text/css" rel="stylesheet"/>
    	<script type="text/javascript" src="js/jquery.min.js"></script>
		<script src="js/common.js" type="text/javascript" charset="utf8"></script>
	</head>
	<body>
    	<div class="container-fluid">
      		<div class="row-fluid">
        		<div class="span12">
          				<h3>
          					FULL SQL
          					<a id="viewJsonApi" target="_blank">View JSON API</a>
          				</h3>
						<h5 id="fullSql"></h5>
						<h2> Format View:</h2>
					   	<textarea style='width:99%;height:120px;;border:1px #A8C7CE solid;line-height:20px;font-size:12px;' id="formattedSql">
					  	</textarea>
					  	<br/>
				      	<br/>
				      	<h3> Parse View:</h3>
				      	<table class="table table-bordered" style="background-color: #fff">
				        	<tr>
				          		<td class='td_lable' width='130'> Tables</td>
				          		<td id="parsedtable"></td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable'> Fields</td>
				          		<td id="parsedfields"></td>
				        	</tr>
				        	<tr> 
				        		<td class='td_lable'> Coditions</td>
				          		<td id="parsedconditions"> </td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable'> Relationships</td>
				          		<td id="parsedrelationships"></td>
				       		</tr>
				        	<tr>
				          		<td class='td_lable'> OrderByColumns</td>
				          		<td id="parsedorderbycolumns"></td>
				        	</tr>
				      	</table>
				      	<br />
				      
				      	<h3> LastSlow View:</h3>
				      	<table class="table table-bordered" style="background-color: #fff">
				       		<tr>
				          		<td class='td_lable' width='130'>MaxTimespan</td>
				          		<td id="MaxTimespan"></td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable' width='130'>MaxTimespanOccurTime</td>
				          		<td id="MaxTimespanOccurTime"></td>
				        	</tr>
				         	<tr>
				          		<td class='td_lable' width='130'>LastSlowParameters</td>
				          		<td id="LastSlowParameters"></td>
				        	</tr>
				      	</table>
				      	<br/>
				      
				      	<h3> Last Error View:</h3>
				      	<table class="table table-bordered" style="background-color: #fff">
				       		<tr>
				          		<td class='td_lable' width='130'>LastErrorMessage</td>
				          		<td id="LastErrorMessage"></td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable'>LastErrorClass</td>
				          		<td id="LastErrorClass"></td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable'>LastErrorTime</td>
				          		<td id="LastErrorTime"></td>
				        	</tr>
				         	<tr>
				          		<td class='td_lable'>LastErrorStackTrace</td>
				          		<td id="LastErrorStackTrace"></td>
				        	</tr>
				      	</table>
				      	<br/>
				      
				      	<h3>Other View:</h3>
				      	<table class="table table-bordered" style="background-color: #fff">
				       		<tr>
				          		<td class='td_lable' width='130'>BatchSizeMax</td>
				          		<td id="BatchSizeMax"></td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable'>BatchSizeTotal</td>
				          		<td id="BatchSizeTotal"></td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable'>BlobOpenCount</td>
				          		<td id="BlobOpenCount"></td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable'>ClobOpenCount</td>
				          		<td id="ClobOpenCount"></td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable'>ReaderOpenCount</td>
				          		<td id="ReaderOpenCount"></td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable'>InputStreamOpenCount</td>
				          		<td id="InputStreamOpenCount"></td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable'>ReadStringLength</td>
				          		<td id="ReadStringLength"></td>
				        	</tr>
				        	<tr>
				          		<td class='td_lable'>ReadBytesLength</td>
				          		<td id="ReadBytesLength"></td>
				        	</tr>
				      	</table>
				      	<div class="container">
				      		<a class="btn btn-primary" href="javascript:window.close();">Close</a>
				      	</div>
        		</div>
      		</div> 
    	</div>
    	<script type="text/javascript">
    	$.namespace("druid.sqlDetail");
    	druid.sqlDetail = function () {  
    		var sqlId = druid.common.getUrlVar("sqlId");
    		return  {
    			init : function() {
    				druid.common.buildHead(2);
    				this.ajaxRequestForBasicInfo();
    				$("#viewJsonApi").attr("href", 'sql-' + sqlId + '.json');
    			},
    			
    			ajaxRequestForBasicInfo : function() {
    				$.ajax({
    					type: 'POST',
    					url: 'sql-' + sqlId + '.json',
    					success: function(data) {
    						var sqlInfo = data.Content;
    						if (sqlInfo == null)
    							return;

    						$("#fullSql").text(sqlInfo.SQL)
    						$("#formattedSql").text(sqlInfo.formattedSql)
    						$("#parsedtable").text(sqlInfo.parsedTable)
    						$("#parsedfields").text(sqlInfo.parsedFields)
    						$("#parsedconditions").text(sqlInfo.parsedConditions)
    						$("#parsedrelationships").text(sqlInfo.parsedRelationships)
    						$("#parsedorderbycolumns").text(sqlInfo.parsedOrderbycolumns)
    						
    						$("#MaxTimespanOccurTime").text(sqlInfo.MaxTimespanOccurTime)
    						$("#LastSlowParameters").text(sqlInfo.LastSlowParameters)
    						$("#MaxTimespan").text(sqlInfo.MaxTimespan)
    						
    						$("#LastErrorMessage").text(sqlInfo.LastErrorMessage)
    						$("#LastErrorClass").text(sqlInfo.LastErrorClass)
    						$("#LastErrorTime").text(sqlInfo.LastErrorTime)
    						$("#LastErrorStackTrace").text(sqlInfo.LastErrorStackTrace)
    						
    						$("#BatchSizeMax").text(sqlInfo.BatchSizeMax)
    						$("#BatchSizeTotal").text(sqlInfo.BatchSizeTotal)
    						$("#BlobOpenCount").text(sqlInfo.BlobOpenCount)
    						$("#ClobOpenCount").text(sqlInfo.ClobOpenCount)
    						$("#InputStreamOpenCount").text(sqlInfo.InputStreamOpenCount)
    						$("#ReaderOpenCount").text(sqlInfo.ReaderOpenCount)
    						$("#ReadStringLength").text(sqlInfo.ReadStringLength)
    						$("#ReadBytesLength").text(sqlInfo.ReadBytesLength)
    					},
    					dataType: "json"
    				});
    			}
    		}
    	}();

    	$(document).ready(function() {
    		druid.sqlDetail.init();
    	});
    	</script>
	</body>
</html>
